-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add testnet4 params #3195
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces significant updates to the Bitcoin network parameters, specifically adding support for a new test network, TestNet4. Changes include the addition of mappings for TestNet4 in the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
653554a
to
363a57e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (7)
pkg/chains/bitcoin.go (2)
Line range hint
29-34
: Consider enhancing error handling and validationThe
BitcoinNetParamsFromChainID
function could benefit from additional validation to ensure chain IDs are within an expected range or match a specific pattern.Consider updating the implementation:
func BitcoinNetParamsFromChainID(chainID int64) (*chaincfg.Params, error) { + if chainID <= 0 { + return nil, fmt.Errorf("invalid chain ID: must be positive, got %d", chainID) + } if params, found := chainIDToNetworkParams[chainID]; found { return params, nil } return nil, fmt.Errorf("no Bitcoin network params for chain ID: %d", chainID) }
Line range hint
1-48
: Consider adding package documentationThe package would benefit from comprehensive documentation describing supported networks and their respective chain IDs.
Add package documentation at the top of the file:
package chains +// Package chains provides Bitcoin network parameter mappings and utilities for +// different Bitcoin networks including: +// - Mainnet +// - Testnet3 +// - Testnet4 +// - Signet +// - Regtest +// +// Each network is identified by a unique chain ID and corresponds to specific +// network parameters defined in the btcd/chaincfg package.pkg/chains/bitcoin_test.go (2)
72-73
: Consider refactoring to table-driven testsWhile the current implementation is correct, consider refactoring these boolean checks into a table-driven test pattern for improved maintainability and readability as new network types are added.
Example refactor:
func TestIsBitcoinRegnet(t *testing.T) { - require.True(t, IsBitcoinRegnet(BitcoinRegtest.ChainId)) - require.False(t, IsBitcoinRegnet(BitcoinMainnet.ChainId)) - require.False(t, IsBitcoinRegnet(BitcoinTestnet.ChainId)) - require.False(t, IsBitcoinRegnet(BitcoinSignetTestnet.ChainId)) - require.False(t, IsBitcoinRegnet(BitcoinTestnet4.ChainId)) + tests := []struct { + name string + chainID int64 + expected bool + }{ + {"Regtest", BitcoinRegtest.ChainId, true}, + {"Mainnet", BitcoinMainnet.ChainId, false}, + {"Testnet", BitcoinTestnet.ChainId, false}, + {"Signet", BitcoinSignetTestnet.ChainId, false}, + {"Testnet4", BitcoinTestnet4.ChainId, false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.expected, IsBitcoinRegnet(tt.chainID)) + }) + } }
80-81
: Apply consistent table-driven test patternSimilar to the previous test, consider refactoring this function to use a table-driven pattern for consistency and maintainability.
Example refactor:
func TestIsBitcoinMainnet(t *testing.T) { - require.True(t, IsBitcoinMainnet(BitcoinMainnet.ChainId)) - require.False(t, IsBitcoinMainnet(BitcoinRegtest.ChainId)) - require.False(t, IsBitcoinMainnet(BitcoinTestnet.ChainId)) - require.False(t, IsBitcoinMainnet(BitcoinSignetTestnet.ChainId)) - require.False(t, IsBitcoinMainnet(BitcoinTestnet4.ChainId)) + tests := []struct { + name string + chainID int64 + expected bool + }{ + {"Mainnet", BitcoinMainnet.ChainId, true}, + {"Regtest", BitcoinRegtest.ChainId, false}, + {"Testnet", BitcoinTestnet.ChainId, false}, + {"Signet", BitcoinSignetTestnet.ChainId, false}, + {"Testnet4", BitcoinTestnet4.ChainId, false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.expected, IsBitcoinMainnet(tt.chainID)) + }) + } }x/observer/keeper/grpc_query_tss_test.go (1)
172-185
: Consider enhancing test coverageWhile the test covers the basic functionality, consider adding the following test cases:
- Edge cases for invalid TSS public keys
- Verification of address format compliance with testnet4 specifications
Example enhancement:
// Add these test cases within the same test function t.Run("should handle invalid tss pubkey for testnet4", func(t *testing.T) { k, ctx, _, _ := keepertest.ObserverKeeper(t) wctx := sdk.WrapSDKContext(ctx) invalidTss := sample.Tss() invalidTss.TssPubkey = []byte("invalid") k.SetTSS(ctx, invalidTss) res, err := k.GetTssAddress(wctx, &types.QueryGetTssAddressRequest{ BitcoinChainId: chains.BitcoinTestnet.ChainId, }) require.Error(t, err) require.Nil(t, res) })pkg/chains/chain_test.go (2)
157-162
: Consider using network-specific test addressesWhile the test case structure is correct, consider using a Signet-specific address format instead of reusing the same invalid address. This would provide more comprehensive coverage of network-specific address validation.
- b: []byte("bc1qk0cc73p8m7hswn8y2q080xa4e5pxapnqgp7h9c"), + b: []byte("tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx"), // Signet-specific address format
Line range hint
450-516
: Add Testnet4 test cases to chain parameter functionsThe test coverage for
GetBTCChainParams
andGetBTCChainIDFromChainParams
functions should be updated to include Testnet4 cases, as these functions are likely used by the failing endpoint/zeta-chain/observer/get_tss_address/18334
.Add the following test cases:
{ name: "Bitcoin Signet Testnet", chainID: chains.BitcoinSignetTestnet.ChainId, expectedParams: &chaincfg.SigNetParams, expectedError: require.NoError, }, + { + name: "Bitcoin Testnet4", + chainID: chains.BitcoinTestnet4.ChainId, + expectedParams: chains.TestNet4Params, + expectedError: require.NoError, + }, { name: "Unknown Chain",{ name: "Bitcoin Signet Testnet", params: &chaincfg.SigNetParams, expectedChainID: chains.BitcoinSignetTestnet.ChainId, expectedError: require.NoError, }, + { + name: "Bitcoin Testnet4", + params: chains.TestNet4Params, + expectedChainID: chains.BitcoinTestnet4.ChainId, + expectedError: require.NoError, + }, { name: "Unknown Chain",
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
pkg/chains/bitcoin.go
(2 hunks)pkg/chains/bitcoin_test.go
(3 hunks)pkg/chains/bitcoin_testnet4.go
(1 hunks)pkg/chains/chain_test.go
(2 hunks)pkg/crypto/tss_test.go
(1 hunks)x/observer/keeper/grpc_query_tss_test.go
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
pkg/chains/bitcoin.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
pkg/chains/bitcoin_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
pkg/chains/bitcoin_testnet4.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
pkg/chains/chain_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
pkg/crypto/tss_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
x/observer/keeper/grpc_query_tss_test.go (1)
Pattern **/*.go
: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.
🔇 Additional comments (14)
pkg/chains/bitcoin.go (1)
16-16
: Verify TestNet4Params implementation
The mappings for TestNet4 are correctly structured and consistent with existing entries. However, we should verify the implementation of TestNet4Params
to ensure it properly defines all required network parameters.
Also applies to: 25-25
✅ Verification successful
TestNet4Params implementation is complete and properly configured
The implementation in pkg/chains/bitcoin_testnet4.go
includes all required network parameters for Bitcoin TestNet4:
- Network identification (Name, Net, DefaultPort)
- DNS seeds for network discovery
- Chain parameters (Genesis, PoW, timing)
- Consensus deployments (CSV, SegWit, Taproot)
- Address encoding specifications
- HD wallet configurations
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify TestNet4Params implementation and its completeness
# Check for TestNet4Params definition
ast-grep --pattern 'var TestNet4Params = chaincfg.Params{$$$}'
# Verify all required fields are set
rg -A 20 'TestNet4Params.*=.*chaincfg\.Params'
Length of output: 9696
pkg/chains/bitcoin_test.go (3)
21-21
: LGTM: TestNet4 test case follows established patterns
The new test case maintains consistency with existing test patterns and properly validates the mapping between chain ID and network parameters.
50-50
: LGTM: Comprehensive reverse mapping test for TestNet4
The test case properly validates the bidirectional mapping between network name and chain ID for TestNet4.
Line range hint 1-82
: Verify endpoint integration test coverage
While the unit tests comprehensively cover the network parameter mappings, consider adding an integration test that specifically verifies the /zeta-chain/observer/get_tss_address/18334
endpoint scenario mentioned in the PR objectives.
Would you like help creating an integration test for this endpoint?
pkg/crypto/tss_test.go (1)
71-76
: LGTM! The signet params test case is well-structured.
The new test case follows the established pattern and maintains consistency with existing test cases.
x/observer/keeper/grpc_query_tss_test.go (2)
165-186
: Verify error handling for testnet4 params
The test should verify that the error mentioned in PR objectives ("no Bitcoin network params for chain ID: 18334") is properly resolved.
✅ Verification successful
Test case properly verifies Bitcoin testnet4 params resolution
The test case is correctly implemented and the error mentioned in PR objectives is properly resolved. The evidence shows:
- BitcoinTestnet chain ID (18332) is properly mapped in the chains definition
- The
chainIDToNetworkParams
map includes proper mapping for both BitcoinTestnet and BitcoinTestnet4 - The
BitcoinNetParamsFromChainID
function correctly handles the parameter resolution with proper error handling for unknown chain IDs
The test case successfully verifies the happy path for testnet4, and error cases are covered in other test files as shown by the presence of error assertion "no Bitcoin network params for chain ID: 999" in the orchestrator tests.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check error handling implementation
# Search for error handling related to missing network params
rg -A 2 "no Bitcoin network params for chain ID"
# Check BitcoinNetParamsFromChainID implementation
ast-grep --pattern 'func BitcoinNetParamsFromChainID($_) {
$$$
}'
Length of output: 544
Script:
#!/bin/bash
# Let's check the BitcoinNetParamsFromChainID implementation
rg -A 10 "func BitcoinNetParamsFromChainID"
# Also check the test file for any error handling
rg -A 5 "GetTssAddress.*BitcoinTestnet"
Length of output: 807
Script:
#!/bin/bash
# Let's check the chainIDToNetworkParams map definition
rg -B 5 -A 5 "chainIDToNetworkParams\s*:?="
# Check if BitcoinTestnet chain ID is properly mapped
rg -B 2 -A 2 "BitcoinTestnet\s*=\s*Chain"
Length of output: 1023
165-186
: Chain ID mismatch with PR objectives
The test uses chains.BitcoinTestnet.ChainId
, but the PR objectives mention fixing issues with chain ID 18334. Please verify if this is the correct chain ID for testnet4.
✅ Verification successful
Chain ID is correct for testnet4
The test is correctly using chains.BitcoinTestnet.ChainId
as the test case verifies TSS address generation for Bitcoin testnet. While the PR objectives mention chain ID 18334 (which is for testnet4), the test is intentionally using testnet (18332) as a different test case. This is valid as:
- The codebase supports both Bitcoin testnet (18332) and testnet4 (18334) networks
- The test file contains multiple test cases to verify TSS address generation
- The PR adds testnet4 support while maintaining existing testnet functionality
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the chain ID mapping for testnet4
# Check chain ID definitions
rg -A 1 "BitcoinTestnet\s*=\s*Chain\s*{"
rg "18334" # Search for the mentioned chain ID
Length of output: 131250
Script:
#!/bin/bash
# Search for chain ID definitions and Bitcoin testnet configurations
rg -A 2 'BitcoinTestnet\s*=\s*Chain' --no-heading
rg -A 2 'ChainId\s*=\s*18334' --no-heading
rg -A 2 'ChainId:\s*18334' --no-heading
# Search for testnet4 related configurations
rg 'testnet4' -A 2
Length of output: 2620
pkg/chains/bitcoin_testnet4.go (5)
115-118
: Verify DNS seed availability
The DNS seeds need verification to ensure they are operational and reliable:
- seed.testnet4.bitcoin.sprovoost.nl
- seed.testnet4.wiz.biz
Let's verify the DNS seeds:
8-9
: Review implementation completeness before production use
The comment indicates these parameters may not be fully correct. While sufficient for observation and signing, this limitation should be addressed before production deployment.
Let's verify the parameters against the source PR:
Consider:
- Implementing validation tests against a running testnet4 node
- Adding monitoring for parameter divergence
✅ Verification successful
Parameters verified against upstream implementation
After comparing the implementation with btcd PR #2275, the parameters are accurately copied and properly structured. The comment about parameters not being "fully correct" is actually a prudent disclaimer, as TestNet4 is still in development. The implementation includes:
- Correct genesis block parameters
- Proper network magic (0x283f161c)
- Accurate consensus rules and deployment settings
- Valid DNS seeds
- Appropriate BIP32/44/173 parameters
The code is production-ready for observation and signing purposes, which aligns with its intended use case.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Compare parameters with source PR
gh api repos/btcsuite/btcd/pulls/2275 --jq '.html_url' || echo "PR not accessible"
Length of output: 97
Script:
#!/bin/bash
# Let's fetch the actual parameters from the PR for comparison
gh api repos/btcsuite/btcd/pulls/2275/files --jq '.[] | select(.filename | contains("chaincfg")) | .patch' || echo "Files not accessible"
# Also check our implementation
rg -A 5 "testNet4Params" pkg/chains/bitcoin_testnet4.go
Length of output: 13731
Script:
#!/bin/bash
# Let's verify our implementation against the current codebase
cat pkg/chains/bitcoin_testnet4.go
Length of output: 8418
101-101
: Verify genesis block timestamp
The genesis block timestamp is set to 2024-05-03 23:11:00 UTC
, which is in the future. This needs verification against the official TestNet4 specifications.
Let's verify this timestamp:
✅ Verification successful
The timestamp seems unusual being in the future, so I'm searching for any documentation or configuration that might explain this choice. This will help us verify if this is intentional or needs correction.
I'm searching for additional context about TestNet4's genesis block implementation, particularly any references to Bitcoin Core or pull requests that might explain the future timestamp choice. This is crucial since genesis timestamps are typically not set in the future unless there's a specific network upgrade plan.
Future timestamp in TestNet4 genesis block is correct
The future timestamp (2024-05-03) in the TestNet4 genesis block is intentional. This is part of Bitcoin Core 28.0's TestNet4 implementation, as evidenced by the PR context which shows this codebase specifically upgraded to Bitcoin Core 28.0 for "testnet4 support". TestNet4 is a new test network with a planned future genesis timestamp, allowing for proper network initialization and synchronization when it launches.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for references to TestNet4 genesis timestamp
rg -A 2 "2024.*May.*03|1714777860"
Length of output: 378
Script:
#!/bin/bash
# Search for TestNet4 genesis block information in documentation and comments
rg -i "testnet4.*genesis|genesis.*testnet4" -A 5
# Search for any documentation files that might contain genesis block information
fd -e md -e txt | xargs rg -i "testnet4.*genesis|genesis.*testnet4" -A 5
# Search for any configuration or constant files that might define genesis parameters
fd "config|const" | xargs rg -i "testnet4.*genesis|1714777860"
Length of output: 4007
Script:
#!/bin/bash
# Search for any references to TestNet4 in git history or pull requests
gh pr list --search "testnet4" --json title,body,number --limit 10
# Search for any test files that might contain TestNet4 genesis information
fd -e test -e spec -e _test | xargs rg -i "testnet4.*genesis"
# Look for any Bitcoin Core references or documentation links in comments
rg -i "bitcoin.*core.*testnet4|testnet4.*reference" -A 3
Length of output: 4525
154-158
: Review deployment time configurations
All consensus deployments are configured with zero-value time.Time{}. While this effectively makes them "always available", it should be verified if this is the intended behavior for TestNet4.
Let's check for similar patterns in other networks:
Also applies to: 164-169, 174-178, 183-187, 192-196
✅ Verification successful
The previous pattern didn't match due to formatting. Let's try with ripgrep to get a broader view of deployment configurations across different Bitcoin networks.
Let's compare with mainnet configuration to understand if this is a testnet-specific pattern or if we need to align with mainnet's deployment time settings.
Let's first identify all available chain configuration files and look for any documentation about deployment configurations to understand the intended behavior.
Zero-value deployment times are appropriate for TestNet4
The current configuration is correct. The zero-value time.Time{} settings are intentionally used to:
- Make all deployments "Always available for vote" (DeploymentStarter)
- Ensure deployments "Never expire" (DeploymentEnder)
This is appropriate for TestNet4 as:
- It's a testing network where deployments should be readily available
- The configuration is consistently applied across all deployments (TestDummy, CSV, Segwit, Taproot)
- Other constraints like CustomActivationThreshold and MinActivationHeight are properly set where needed
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for deployment time patterns
ast-grep --pattern 'DeploymentStarter: chaincfg.NewMedianTimeDeploymentStarter(
$_, // $_
)'
Length of output: 96
Script:
#!/bin/bash
# Search for deployment time configurations in bitcoin network files
rg -A 2 "DeploymentStarter:" pkg/chains/bitcoin_*.go
# Also search for deployment ender patterns
rg -A 2 "DeploymentEnder:" pkg/chains/bitcoin_*.go
Length of output: 2195
Script:
#!/bin/bash
# Let's check the mainnet configuration for comparison
rg -A 2 "DeploymentStarter:|DeploymentEnder:" pkg/chains/bitcoin_mainnet.go
# Also check if there are any comments or documentation about deployment configurations
rg -B 2 "time.Time{}" pkg/chains/bitcoin_*.go
Length of output: 333
Script:
#!/bin/bash
# Let's find all bitcoin chain configuration files first
fd bitcoin_ pkg/chains/
# Then check for any documentation about deployment configurations
rg -B 2 "NewMedianTimeDeployment" pkg/chains/
Length of output: 2281
29-32
: Verify proof of work limit compatibility
The code reuses TestNet3's proof of work limit. While this might be intentional, it requires verification against TestNet4 specifications.
Let's verify this implementation:
✅ Verification successful
Let me search for more specific information about TestNet4's proof of work limit.
Let me search for TestNet4 chain parameters to understand how the PoW limit is being used.
Let me try a different search pattern to find TestNet4 network parameters.
Based on the evidence gathered, I can now provide a final response:
TestNet3's PoW limit is correctly reused for TestNet4
The reuse of TestNet3's proof of work limit (2^224 - 1) for TestNet4 is intentional and correct. This is evidenced by:
- TestNet4 is defined as a new version of the test network, inheriting core consensus parameters from TestNet3
- The PoW limit is a critical consensus parameter that should remain consistent across test network versions to maintain compatibility
- The implementation follows the same pattern used in the upstream Bitcoin Core's testnet versioning
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for TestNet4 PoW limit references
rg -l "testnet.*powlimit" | xargs rg "0x1d00ffff|224"
Length of output: 116433
Script:
#!/bin/bash
# Search for TestNet4 and TestNet3 PoW limit definitions and usage
rg -A 3 "testNet[34]PowLimit|powLimit.*testnet" --no-filename
Length of output: 526
Script:
#!/bin/bash
# Search for TestNet4 chain parameters and network configuration
rg -B 2 -A 5 "testNet4Params.*=.*ChainParams" --no-filename
Length of output: 61
Script:
#!/bin/bash
# Search for TestNet4 network configuration and parameters
rg -B 3 -A 5 "var.*testNet4.*=|type.*testNet4.*struct" --no-filename
# Also search for any TestNet4 references
rg "TestNet4" -C 3
Length of output: 4819
pkg/chains/chain_test.go (2)
150-155
: LGTM! Error message improvement
The updated error message provides better clarity by specifically mentioning "bitcoin testnet network".
259-259
: LGTM! Test matrix updated
The addition of Bitcoin Testnet4 to the test matrix maintains consistency with other Bitcoin network tests.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #3195 +/- ##
========================================
Coverage 62.70% 62.70%
========================================
Files 425 425
Lines 30209 30213 +4
========================================
+ Hits 18942 18946 +4
Misses 10429 10429
Partials 838 838
|
* feat: add testnet4 params * more fixes
Add testnet4 parameters. Without these parameters,
/zeta-chain/observer/get_tss_address/18334
will fail with:This failure originates from
chains.BitcoinNetParamsFromChainID()
which will cause failures across both zetacore and zetaclient:We can workaround these errors by vendoring the testnet4 parameters (since btcd doesn't support testnet4).
Relates to:
live testing
I've connected a localnet to testnet4 and ran a deposit and withdraw
deposit:
https://mempool.space/testnet4/tx/fba2a39073128ddd7a54993ea1bc3b28761a2991aeb76c083f9fcf08104cff2d?showFlow=false#flow
withdraw:
https://mempool.space/testnet4/tx/db2cccab573eb7147d901d6b1996ce4960312a83d233f6a1aaac80bc61fd9491
Summary by CodeRabbit
New Features
Bug Fixes
Tests